package String类;

/**
 * @作者:侯国威
 * @时间: 2020/4/13/15:08
 * @邮箱:1045077189@qq.com
 */
public class StringCount {
    public static void main(String[] args) {
        StringCount count =new StringCount();
        count.Count("ABCDTDNSJKFHAB","AB");

    }

    public int Count(String s, String  targetString ) {
        int max = s.length();
        int subString = targetString.length();
        int count = 0;
        int index;
        if (max >= subString) {
            if ((index = s.indexOf(targetString)) != -1) {
                count++;
                targetString = targetString.substring(index + targetString.length());
                System.out.println(count);
            }
                return count;
        }else {
            return 0;
        }


    }

}
